//
//  Addbook.m
//  OC08_Category_Extension_Protocol
//
//  Created by Scott on 16/4/27.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "Addbook.h"
#import "Contect.h"

// 延展.
@interface Addbook ()

@property (nonatomic, retain) NSMutableArray *arr;

@end


@implementation Addbook

- (instancetype)init {
    
    self = [super init];
    if (self) {
        self.arr = [NSMutableArray array];
    }
    
    return self;

}

- (void)showAllContact {
    
    for (Contect *con in self.arr) {
        
        NSLog(@"con:%@", con.name);
        
    }

}

- (void)addContact:(Contect *)con {
    
    [self.arr addObject:con];
    
}

- (NSArray<Contect *> *)searchContactWithName:(NSString *)name {

    NSMutableArray *mArr = [NSMutableArray array];
    
    for (Contect *con in self.arr) {
        
        if ([con.name isEqualToString:name]) {
            
            [mArr addObject:con];
            
        }
    }
    
    return mArr;
}


- (void)deleteContactWithName:(NSString *)name {
    
    NSMutableArray *mArr = [NSMutableArray array];
    
    for (Contect *con in self.arr) {
        
        if ([con.name isEqualToString:name]) {
            
            [mArr addObject:con];
        }
        
    }
    
    [self.arr removeObjectsInArray:mArr];
    
    
    
}






@end
